#include <bits/stdc++.h>
#define ll long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

inline static ll read(){
    ll sum=0; int neg=0,ch=getchar();
    while(!isdigit(ch)) neg|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar();
    return neg?-sum:sum;
}

int n; ll arr[30000];
signed main(){
    freopen("kte.in","r",stdin);
    freopen("kte.out","w",stdout);
    ll sum=0;
    for(int T=read();T;T--){
        ll x=read(),*it=lower_bound(arr,arr+n,x),l=0,r=0,ans=0;
        if(*it==x) memmove(it,it+1,8*(arr+n-it)),arr[--n]=0,sum-=x;
        else memmove(it+1,it,8*(arr+n-it)+8),n++,*it=x,sum+=x;
        for(int i=0;i<n;r+=arr[n-i-1],i++) if((l+=arr[i])>r) ans+=r-l;
        printf("%lld\n",ans+sum);
    } return 0;
}
